home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / net / amitcp2_x_gcc.lha / RCS.RCSfiles / gethostname.c,v < prev    next >
Text File  |  1994-01-12  |  4KB  |  205 lines

  1. head    1.5;
  2. access;
  3. symbols;
  4. locks
  5.     jasegler:1.5; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.5
  10. date    94.01.12.18.35.20;    author jasegler;    state Exp;
  11. branches;
  12. next    1.4;
  13.  
  14. 1.4
  15. date    94.01.11.19.53.25;    author jasegler;    state Exp;
  16. branches;
  17. next    1.3;
  18.  
  19. 1.3
  20. date    94.01.11.19.21.04;    author jasegler;    state Exp;
  21. branches;
  22. next    1.2;
  23.  
  24. 1.2
  25. date    94.01.11.19.16.51;    author jasegler;    state Exp;
  26. branches;
  27. next    1.1;
  28.  
  29. 1.1
  30. date    94.01.11.19.05.28;    author jasegler;    state Exp;
  31. branches;
  32. next    ;
  33.  
  34.  
  35. desc
  36. @@
  37.  
  38.  
  39. 1.5
  40. log
  41. @*** empty log message ***
  42. @
  43. text
  44. @char RCS_ID_GETHOSTNAME_C[] = "$Id: gethostname.c,v 1.4 1994/01/11 19:53:25 jasegler Exp jasegler $";
  45. /*
  46.  * gethostname.c -- get host name from the environment variable "HOSTNAME"
  47.  *
  48.  * Author: jraja <Jarno.Rajahalme@@hut.fi>
  49.  *
  50.  * Copyright © 1993 AmiTCP/IP Group, <amitcp-group@@hut.fi>
  51.  *                  Helsinki University of Technology, Finland.
  52.  *                  All rights reserved.
  53.  *
  54.  * Created      : Tue Apr 27 17:49:15 1993 jraja
  55.  * Last modified: Fri Jun  4 01:58:48 1993 ppessi
  56.  *
  57.  */
  58.  
  59. #include <stdlib.h>
  60. #include <stdio.h>
  61. #include <string.h>
  62. #include <errno.h>
  63.  
  64. /****** net.lib/gethostname ******************************************
  65.  
  66.  *   NAME
  67.  *       gethostname -- get the name of the host
  68.  *
  69.  *   SYNOPSIS
  70.  *       error = gethostname(name, namelen);
  71.  *
  72.  *       int gethostname(char *, int);
  73.  *
  74.  *   FUNCTION
  75.  *       Get the name of the host to the buffer name of length namelen.
  76.  *       The name is taken from the environment variable "HOSTNAME"
  77.  *       where it SHOULD reside.
  78.  *
  79.  *   INPUTS
  80.  *       name    - Pointer to the buffer where the name should be
  81.  *                 stored.
  82.  *       namelen - Length of the buffer name.
  83.  *
  84.  *   RESULT
  85.  *       error   - 0 on success, -1 in case of an error. The global
  86.  *                 variable errno will be set to indicate the error as
  87.  *                 follows:
  88.  *
  89.  *                 ENOENT - The environment variable "HOSTNAME" is not
  90.  *                          found.
  91.  *
  92.  *   EXAMPLE
  93.  *       char hostname[MAXHOSTNAMELEN];
  94.  *       int error;
  95.  *
  96.  *       error = gethostname(hostname, sizeof(hostname));
  97.  *       if (error < 0)
  98.  *         exit(10);
  99.  *
  100.  *       printf("My name is \"%s\".\n", hostname);
  101.  *
  102.  *   NOTES
  103.  *       This function is included for source compatibility with Unix
  104.  *       systems.
  105.  *       The ENOENT errno value is AmiTCP/IP addition.
  106.  *
  107.  *   BUGS
  108.  *       Unlike the Unix version, this version assures that the
  109.  *       resulting string is always NULL-terminated.
  110.  *
  111.  *   SEE ALSO
  112.  *       getenv()
  113.  *****************************************************************************
  114.  *
  115.  */
  116.  
  117. int
  118. gethostname (char *name, int namelen)
  119. {
  120.   char Buffer[80];
  121.   char *cp = getenv ("HOSTNAME");
  122.  
  123.   if (cp == NULL)
  124.     {
  125.       errno = ENOENT;
  126.       return -1;
  127.     }
  128.   /* used to use a function called stccpy.. didn't have it but I figured it
  129.      does something like this.. :) */
  130.   sprintf (Buffer, "%%%ds", namelen);
  131.   sprintf (name, Buffer, cp);
  132.   free (cp);
  133.   return 0;
  134. }
  135. @
  136.  
  137.  
  138. 1.4
  139. log
  140. @*** empty log message ***
  141. @
  142. text
  143. @d1 1
  144. a1 1
  145. char RCS_ID_C[] = "$Id: gethostname.c,v 1.3 1994/01/11 19:21:04 jasegler Exp jasegler $";
  146. @
  147.  
  148.  
  149. 1.3
  150. log
  151. @*** empty log message ***
  152. @
  153. text
  154. @d1 1
  155. a1 1
  156. char RCS_ID_C[] = "$Id: gethostname.c,v 1.1 1994/01/11 19:05:28 jasegler Exp jasegler $";
  157. d17 1
  158. @
  159.  
  160.  
  161. 1.2
  162. log
  163. @*** empty log message ***
  164. @
  165. text
  166. @d84 2
  167. a87 2
  168.   printf ("GETHOSTNAME: Buffer %s\n", Buffer);
  169.   strcpy (name, cp);
  170. @
  171.  
  172.  
  173. 1.1
  174. log
  175. @Initial revision
  176. @
  177. text
  178. @d1 1
  179. a1 1
  180. RCS_ID_C = "$Id: gethostname.c,v 1.3 1993/06/03 22:59:38 ppessi Exp $";
  181. d21 2
  182. a22 2
  183.  *
  184.  *   NAME   
  185. d43 1
  186. a43 1
  187.  *                 follows: 
  188. d47 1
  189. a47 1
  190.  *  
  191. d51 1
  192. a51 1
  193.  *       
  194. d55 1
  195. a55 1
  196.  *       
  197. d73 1
  198. a73 1
  199. int 
  200. d76 1
  201. d84 4
  202. a87 1
  203.   stccpy (name, cp, namelen);
  204. @
  205.